//
//    Copyright (C) 2012  OinkStudio
//
//    This program is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    This program is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with this program.  If not, see <http://www.gnu.org/licenses/>.

package oldClasses;

import java.util.ArrayList;

public class DadesTotal {
	private ArrayList<Taula> totalDades = new ArrayList<Taula>();
	
	
	public void addTaula(Taula taulaNova){
		totalDades.add(taulaNova);
	}
	
	public void addRow(String taulaAdd,ArrayList<Object> row){
		getTaula(taulaAdd).getDadesTaula().getArrayRow().add(row);
	}
	public int size(){
		return totalDades.size();
	}
	public Taula getTaula(String nomTaula){
		for(int i=0; i<totalDades.size();i++){
			if(nomTaula.equals(totalDades.get(i).getNomTaula())){
				return totalDades.get(i);
			}
		}
		return null;
	}
	
	public Taula getTaula(int i){
		return totalDades.get(i);
	}
	
	public void setValor(String nomTaula,String nomCamp,int row,Object valor){		
		getTaula(nomTaula).getDadesTaula().setValor(nomCamp,row,valor);
	}
	
	public void setValor(String nomTaula,int numCamp,int row,Object valor){		
		getTaula(nomTaula).getDadesTaula().setValor(numCamp,row,valor);
	}
	
	public Object getValor(String nomTaula,String nomCamp,int row){		
		return getTaula(nomTaula).getDadesTaula().getValor(nomCamp,row);
	}
	
	/**Rows que compleixen que un camp d'una taula sigui igual al objecte 'objecteIgual'***/
	public ArrayList<ArrayList<Object>> rowWhereEquals(String nomTaula,String nomCamp,Object objecteIgual){
		ArrayList<ArrayList<Object>> auxTable = new ArrayList<ArrayList<Object>>();
		for (int i = 0; i<getTaula(nomTaula).getDadesTaula().getArrayRow().size();i++)
			if (getTaula(nomTaula).getDadesTaula().getValor(nomCamp, i).equals(objecteIgual))
				auxTable.add(getTaula(nomTaula).getDadesTaula().getRow(i));				
		return auxTable;
		
	}
}
